"""


"""


from info import create_app, db, models
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand

from info.models import User

app = create_app("develop")
# 创建app的是时候传参数
# 如果传"develop" 表示加载开发模式DevelopmentConfig的配置项
# 如果传"product" 表示加载生产模式ProductionConfig的配置项

# 创建manager对象
manager = Manager(app)
# 创建Migrate对象
Migrate(app, db)
# 添加db命令
manager.add_command("db", MigrateCommand)

# 让我们通过命令行的方式创建管理员用户
@manager.option("-n", dest="name")
@manager.option("-p", dest="password")
def createsuperuser(name, password):

    if not all([name ,password]):
        print("参数不全")
        return

    user = User()
    user.nick_name = name
    user.mobile = name
    user.password = password
    user.is_admin = True

    try:
        db.session.add(user)
        db.session.commit()
        print("创建成功")
        return
    except Exception as e:
        print("创建失败： %s" % e)
        db.session.rollback()



if __name__ == "__main__":
    # print(app.url_map)
    manager.run()